package learn.demo1;

import java.util.ArrayList;
import java.util.Random;

/*
用一个打大的集合存入20个随机数字，筛选偶数放入小集合

*/


public class demo2ArrayList {
    public static ArrayList<Integer> getSamllList(ArrayList<Integer> biglist){
        ArrayList<Integer> smallList=new ArrayList<>();
        for (int i = 0; i < biglist.size(); i++) {
            int num=biglist.get(i);
            if(num%2==0){
                smallList.add(num);
            }
        }
        return smallList;
    }

    public static void main(String[] args) {
        ArrayList<Integer> bigList = new ArrayList<>();
        Random r=new Random();
        for (int i = 0; i < 20; i++) {
            int num=r.nextInt(100)+1;
            bigList.add(num);
        }
        ArrayList<Integer> smalllist=getSamllList(bigList);
        for (int i = 0; i < smalllist.size(); i++) {
            System.out.println(smalllist.get(i));
            

        }
        System.out.println("总共有几个："+smalllist.size());

    }
}
